import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Drawing_Test
{
	public static void main(String[] args)
	{
		Drawing_Test p = new Drawing_Test();
		p.gui();
	}
	
	public void gui()
	{
		// create a JFrame - a JFrame is a main window
		final JFrame myWindow = new JFrame("This is a Swing example!");
		myWindow.setSize(500, 500);
		myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		// create a JPanel - a JPanel is an invisible container for controls
		JPanel pnlNorth = new JPanel();
		pnlNorth.setLayout(new FlowLayout());
		myWindow.add(pnlNorth, BorderLayout.NORTH); // add it to the JFrame
		
		// create a button
		JButton btnHello = new JButton("Hello!");
		pnlNorth.add(btnHello);
		// add code to the button for when it is clicked
		btnHello.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				JOptionPane.showMessageDialog(myWindow, "Hello!");
			}
		});
		
		// create another button
		JButton btnGoodbye = new JButton("Goodbye!");
		pnlNorth.add(btnGoodbye); // add it to the JPanel
		
		// create a CirclePanel and add it to the form
		CirclePanel cp = new CirclePanel();
		myWindow.add(cp, BorderLayout.CENTER);
		
		// show the JFrame
		myWindow.setVisible(true);
	}

	class CirclePanel extends JComponent
	{
		@Override
		public void paintComponent(Graphics g)
		{
			Graphics2D g2d = (Graphics2D)g;
			g2d.drawOval(1, 1, this.getWidth() - 2, this.getHeight() - 2);
		}
	}
}